﻿using System.Web.Optimization;

namespace Azure.Online.Web.App_Start {
    public static class BundleConfig {
        // For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkId=254725
        public static void RegisterBundles(BundleCollection bundles) {
            bundles.Add(new ScriptBundle("~/js/bundles/index.js").Include(
                        "~/js/spa.js",
                        "~/js/common/base64.js",
                        "~/js/common/bindings.js",
                        "~/js/common/date.js",
                        "~/js/common/pager.js",
                        "~/js/common/uri.js",
                        "~/js/common/modal.js",
                        "~/js/crypto.js",
                        "~/js/sha256.js",
                        "~/js/settings.js")
                        .IncludeStorageClient()
                        .IncludeTables()
                        .IncludeBlobs()
                        .IncludeQueues()
                        .IncludeServices()
                        .Include(
                        "~/js/console/newrequest.js",
                        "~/js/console.js",
                        "~/js/accounts/account.js",
                        "~/js/accounts.js",
                        "~/js/azureonline.js")
                //.IncludeFoundation()
            );
        }

        private static Bundle IncludeStorageClient(this Bundle bundle) {
            bundle.Include("~/js/storageclient/azure-account.js");
            bundle.Include("~/js/storageclient/azure-blobs.js");
            bundle.Include("~/js/storageclient/azure-tables.js");
            bundle.Include("~/js/storageclient/azure-queues.js");
            bundle.Include("~/js/storageclient/azure-api.js");
            bundle.Include("~/js/storageclient/azure-request.js");
            bundle.Include("~/js/storageclient/azure-proxy-channel.js");
            bundle.Include("~/js/storageclient/azure-signature.js");
            return bundle;
        }

        private static Bundle IncludeTables(this Bundle bundle) {
            bundle.Include("~/js/tables/edm.js");
            bundle.Include("~/js/tables/record.js");
            bundle.Include("~/js/tables/record-delete.js");
            bundle.Include("~/js/tables/records.js");
            bundle.Include("~/js/tables/schema.js");
            bundle.Include("~/js/tables/table.js");
            bundle.Include("~/js/tables/table-columns.js");
            bundle.Include("~/js/tables/table-create.js");
            bundle.Include("~/js/tables/table-delete.js");
            bundle.Include("~/js/tables/table-markers.js");
            bundle.Include("~/js/tables/table-settings.js");
            bundle.Include("~/js/tables/tables.js");
            bundle.Include("~/js/tables/tables-context.js");
            bundle.Include("~/js/tables.js");
            bundle.IncludeTableQueryBuilder();
            bundle.IncludeTableQueryParser();
            return bundle;
        }

        private static Bundle IncludeTableQueryBuilder(this Bundle bundle) {
            bundle.Include("~/js/tables/query-builder/query-builder.js");
            bundle.Include("~/js/tables/query-builder/query-combine.js");
            bundle.Include("~/js/tables/query-builder/query-compare.js");
            bundle.Include("~/js/tables/query-builder/query-func.js");
            return bundle;
        }

        private static Bundle IncludeTableQueryParser(this Bundle bundle) {
            bundle.Include("~/js/tables/query-parser/query-combine.js");
            bundle.Include("~/js/tables/query-parser/query-compare.js");
            bundle.Include("~/js/tables/query-parser/query-func.js");
            bundle.Include("~/js/tables/query-parser/query-input.js");
            bundle.Include("~/js/tables/query-parser/query-parser.js");
            return bundle;
        }

        private static Bundle IncludeBlobs(this Bundle bundle) {
            bundle.Include("~/js/blobs/blob.js");
            bundle.Include("~/js/blobs/blob-create.js");
            bundle.Include("~/js/blobs/blob-delete.js");
            bundle.Include("~/js/blobs/blob-details.js");
            bundle.Include("~/js/blobs/blob-meta.js");
            bundle.Include("~/js/blobs/blob-props.js");
            bundle.Include("~/js/blobs/blob-resize.js");
            bundle.Include("~/js/blobs/blobs.js");
            bundle.Include("~/js/blobs/blobs-context.js");
            bundle.Include("~/js/blobs/containers.js");
            bundle.Include("~/js/blobs/lease.js");
            bundle.Include("~/js/blobs/container.js");
            bundle.Include("~/js/blobs/container-create.js");
            bundle.Include("~/js/blobs/container-meta.js");
            bundle.Include("~/js/blobs/container-delete.js");
            bundle.Include("~/js/blobs/container-details.js");
            bundle.Include("~/js/blobs/container-props.js");
            bundle.Include("~/js/blobs/blobs.js");
            bundle.Include("~/js/blobs/page-viewer.js");
            bundle.Include("~/js/blobs.js");
            return bundle;
        }

        private static Bundle IncludeQueues(this Bundle bundle) {
            bundle.Include("~/js/queues/messages.js");
            bundle.Include("~/js/queues/message-delete.js");
            bundle.Include("~/js/queues/message-details.js");
            bundle.Include("~/js/queues/queues.js");
            bundle.Include("~/js/queues/queues-context.js");
            bundle.Include("~/js/queues/queue.js");
            bundle.Include("~/js/queues/queue-create.js");
            bundle.Include("~/js/queues/queue-delete.js");
            bundle.Include("~/js/queues/queue-details.js");
            bundle.Include("~/js/queues/queue-meta.js");
            bundle.Include("~/js/queues/queue-props.js");
            bundle.Include("~/js/queues.js");
            return bundle;
        }

        private static Bundle IncludeServices(this Bundle bundle) {
            bundle.Include("~/js/services/meta-editor.js");
            bundle.Include("~/js/services/properties.js");
            return bundle;
        }

        private static Bundle IncludeFoundation(this Bundle bundle) {
            bundle.Include("~/foundation/js/foundation/foundation.js");
            bundle.Include("~/foundation/js/foundation/foundation.forms.js");
            bundle.Include("~/foundation/js/foundation/foundation.topbar.js");
            return bundle;
        }
    }
}